import request from "@/utils/request";
import { API_ENDPOINTS } from "@/config/api";

// 每日挑战接口
export interface DailyChallenge {
  id: number;
  title: string;
  description: string;
  category: "training" | "community" | "learning" | "social";
  difficulty: "easy" | "medium" | "hard";
  points: number;
  time_limit?: number; // 时间限制（秒）
  is_completed: boolean;
  is_claimed: boolean;
  progress?: {
    current: number;
    target: number;
  };
  requirements?: string[];
  icon?: string;
  expires_at?: string;
  created_at: string;
  updated_at?: string;
  joining?: boolean; // 用于UI状态
}

// 每日挑战相关API
export const dailyChallengeApi = {
  // 获取今日挑战
  getTodayChallenge() {
    return request.get<DailyChallenge>("/daily-challenges/today");
  },

  // 获取每日挑战列表
  getDailyChallenges() {
    return request.get<DailyChallenge[]>(API_ENDPOINTS.DAILY_CHALLENGES.LIST);
  },

  // 获取用户每日挑战
  getUserDailyChallenges(userId: number) {
    return request.get<DailyChallenge[]>(
      API_ENDPOINTS.DAILY_CHALLENGES.USER_CHALLENGES(userId)
    );
  },

  // 完成挑战
  completeChallenge(challengeId: number, proofData?: any) {
    return request.post(`/daily-challenges/${challengeId}/complete`, {
      proof_data: proofData,
    });
  },

  // 获取挑战历史
  getChallengeHistory(
    userId: number,
    params?: { page?: number; limit?: number }
  ) {
    return request.get(`/daily-challenges/users/${userId}/history`, { params });
  },
};
